package com.jinyang.baserouter.serialization

import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.SerializationService
import com.jinyang.baserouter.GsonUtils
import com.jinyang.baserouter.log
import java.lang.reflect.Type

/**
 * @Author:         LiuJinYang
 * @CreateDate:     2021/12/8
 * @Description:
 */
@Route(path = "/serialization/gson")
class GsonSerializationServiceImpl : SerializationService {
    override fun init(context: Context?) {
        log("GsonSerializationServiceImpl.init")
    }

    override fun <T : Any?> json2Object(input: String?, clazz: Class<T>?): T? {
        log("GsonSerializationServiceImpl.json2Object")
        return GsonUtils.fromJson(input, clazz)
    }

    override fun object2Json(instance: Any?): String {
        log("GsonSerializationServiceImpl.object2Json")
        return GsonUtils.toJson(instance)
    }

    override fun <T : Any?> parseObject(input: String?, clazz: Type?): T? {
        log("GsonSerializationServiceImpl.parseObject")
        return GsonUtils.fromJson(input, clazz)
    }
}